package com.study.webapp.leetCode_init;

import com.alibaba.fastjson.JSON;

import java.util.*;

public class LeetCode_17 {

    static Map<String, String> map = new HashMap<>(8);
    static List<String> list = new ArrayList<>();
     static  {
        map.put("2", "abc");
        map.put("3", "def");
        map.put("4", "ghi");
        map.put("5", "jkl");
        map.put("6", "mno");
        map.put("7", "pqrs");
        map.put("8", "tuv");
        map.put("9", "wxyz");
    }

    public static void main(String[] args) {
        String digits = "";
        if (digits == null || digits.length() == 0) {
            System.out.println(JSON.toJSONString(list));
            return;
        }
        StringBuilder bf = new StringBuilder();
        bb(0,digits,bf);
        System.out.println(JSON.toJSONString(list));
    }

    public static void bb (int index,String digits,StringBuilder bf) {
         if (index == digits.length()) {
             list.add(bf.toString());
             return;
         }
        char dex = digits.charAt(index);
         String aa = String.valueOf(dex);
        String let = map.get(aa);
        int len = let.length();
        for (int i = 0; i< len;i++) {
            bf.append(let.charAt(i));
            bb(index+1,digits,bf);
            bf.deleteCharAt(bf.length()-1);
        }
    }


}
